package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.service.attr.AttrModifyHelper;
import com.iwhalecloud.bss.kite.cucc.service.attr.LocalAttrHelper;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.CircuitTypeHandler;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.CircuitUsesHandler;
import com.iwhalecloud.bss.kite.event.attr.UpdateAttrValueEvent;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

/**
 * @author 付喆
 * @version 2021/5/24 17:05
 * Description:
 */
@Service
@AttrHandler(CircuitTypeHandler.class)
public class CircuitTypeLinkHandler extends AbstractAttrLinkageHandler<AttrData> {
    @Autowired
    private ApplicationContext applicationContext;

    @Override
    public void handle(KiteAttr kiteAttr, KiteInst kiteInst, AttrData attrData) {
        if(KiteStringUtils.isEmpty(kiteInst.getAttrValue("210004190"))){
            return;
        }
        //数字电路
        if(KiteStringUtils.equals(kiteInst.getAttrValue("210004190"), "1_0000229")){
            LocalAttrHelper.hideAndNullable(kiteInst,
                //电路用途属性、是否划分VLAN属性、VLAN号属性、MTU值属性
                "2_0000006", "2_0000033", "2_0000145", "210004302");
        }
        //以太网电路
        else if(KiteStringUtils.equals(kiteInst.getAttrValue("210004190"), "110007436")){
            AttrModifyHelper.displayAndNullable(kiteInst,
                "2_0000006", "2_0000145", "210004302");
            AttrModifyHelper.displayAndNotNull(kiteInst, "2_0000033");
            UpdateAttrValueEvent updateAttrValueEvent = new UpdateAttrValueEvent(new CircuitUsesHandler(), attrData.getCustId(), attrData.getStaffId());
            updateAttrValueEvent.setInst(kiteInst);
            updateAttrValueEvent.setKiteAttr(kiteAttr);
            updateAttrValueEvent.setAttrData(attrData);
            applicationContext.publishEvent(updateAttrValueEvent);
        }
    }

    @Override
    public void handleStyle(KiteAttr kiteAttr, KiteInst kiteInst, AttrData attrData) {

    }
}
